package das_java_forum_ide;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.DateFormat;
import java.util.GregorianCalendar;

public class neuesprojekt extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField ProjektName;
	private JTextField Publisher;
	private JTextField ErrorMail;
	private JTextField Version;
	public String path;
	private JComboBox ProjektTyp;
	private JTextArea Description;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			neuesprojekt dialog = new neuesprojekt();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public neuesprojekt() {
		setBounds(100, 100, 557, 385);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JLabel lblProjektName = new JLabel("Projekt Name:");
		lblProjektName.setBounds(10, 27, 93, 14);
		contentPanel.add(lblProjektName);
		
		ProjektName = new JTextField();
		lblProjektName.setLabelFor(ProjektName);
		ProjektName.setBounds(113, 24, 418, 20);
		contentPanel.add(ProjektName);
		ProjektName.setColumns(10);
		
		JLabel lblProjektTyp = new JLabel("Projekt Typ:");
		lblProjektTyp.setBounds(10, 62, 93, 14);
		contentPanel.add(lblProjektTyp);
		
		ProjektTyp = new JComboBox();
		lblProjektTyp.setLabelFor(ProjektTyp);
		ProjektTyp.setModel(new DefaultComboBoxModel(new String[] {"Java Projekt", "Java Applet", "Java EE Projekt", "Java FX Projekt", "php-Projekt"}));
		ProjektTyp.setBounds(113, 59, 418, 20);
		contentPanel.add(ProjektTyp);
		
		Publisher = new JTextField();
		Publisher.setBounds(113, 90, 418, 20);
		contentPanel.add(Publisher);
		Publisher.setColumns(10);
		
		ErrorMail = new JTextField();
		ErrorMail.setBounds(113, 121, 418, 20);
		contentPanel.add(ErrorMail);
		ErrorMail.setColumns(10);
		
		Version = new JTextField();
		Version.setBounds(113, 152, 418, 20);
		contentPanel.add(Version);
		Version.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("Publisher:");
		lblNewLabel.setBounds(10, 93, 93, 14);
		contentPanel.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Error Mail:");
		lblNewLabel_1.setBounds(10, 124, 93, 14);
		contentPanel.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Version:");
		lblNewLabel_2.setBounds(10, 155, 93, 14);
		contentPanel.add(lblNewLabel_2);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(113, 183, 418, 102);
		contentPanel.add(scrollPane);
		
		Description = new JTextArea();
		Description.setText("Geben Sie eine Beschreibung ein ....");
		scrollPane.setViewportView(Description);
		
		JLabel lblDescription = new JLabel("Description:");
		lblDescription.setBounds(10, 180, 93, 14);
		contentPanel.add(lblDescription);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						
						
						try {
							
							
							GregorianCalendar calender =  new GregorianCalendar();
							DateFormat Date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
							Projektverwaltung.Main pv = new Projektverwaltung.Main();
							pv.CreateNewProjekt(path, ProjektName.getText(),ProjektTyp.getSelectedItem().toString(), Date.format(calender.getTime()),Publisher.getText(),Version.getText(),Description.getText(),ErrorMail.getText());					
							Main.loadProjekts();
							
							
						} catch (ParserConfigurationException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (TransformerException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
